# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=jucipp
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1403.3134396
pkgrel=1
pkgdesc="A lightweight, cross-platform C++-IDE supporting C++11, C++14, and experimental C++17 features (mingw-w64)"
arch=('any')
url="https://github.com/cppit/jucipp"
license=('MIT')
validpgpkeys=('gpg_KEY')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "git")
depends=("${MINGW_PACKAGE_PREFIX}-clang"
         "${MINGW_PACKAGE_PREFIX}-gtkmm3"
         "${MINGW_PACKAGE_PREFIX}-gtksourceviewmm3"
         "${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-aspell-en")
options=('strip' 'staticlibs')
source=("${_realname}"::"git+https://github.com/cppit/jucipp.git"
        "libclangmm"::"git+https://github.com/cppit/libclangmm.git"
        "tiny-process-library"::"git+https://github.com/eidheim/tiny-process-library.git")
sha256sums=('SKIP'
            'SKIP'
            'SKIP')

pkgver() {
  cd "${srcdir}"/${_realname}
  printf "%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}"/${_realname}
  git submodule init
  git config submodule.libclangmm.url "${srcdir}"/libclangmm
  git config submodule.tiny-process-library.url "${srcdir}"/tiny-process-library
  git submodule update
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -G'MSYS Makefiles' \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      "${extra_config[@]}" \
      ../${_realname}

  make -j1
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make DESTDIR=${pkgdir} install
}
